const WebSocketServer = require('websocket').server;
const http = require('http');

let httpServer = http.createServer((req, res) => {
    res.writeHead(404);
    res.end();
})

let wsServer = new WebSocketServer({
    httpServer: httpServer,
    autoAcceptConnections: true
});

wsServer.on('connect', (connection) => {
    connection.on('message', (message) => {
        console.log(message);
        if(message.type === 'utf8') {
            connection.sendUTF(message.utf8Data);
        }
    });
    connection.on('close', (code, desc) => {
        console.log(code);
        console.log(desc);
    })
});

httpServer.listen(8080, () => {
    console.log(`[${new Date()}] server port: 8080`);
})